package pl.edu.pk.cc.client.chef;

import java.util.List;

import org.hibernate.Session;

import pl.edu.pk.cc.common.dto.CCProjectsDTO;
import pl.edu.pk.cc.common.dto.CCWorkerDTO;

public class CCChefContent {
	public static String statsMenu(){
		List<Object> list = CCChefFunctions.getStats();

		String str = "<h1>Ogolne statystyki firmy</h1>"
				+ "<table id='stats'>"
				+ "<tr><th>Statystyka</th><th>Wartosc</th>"
				+ "</tr>"
				+ "<tr><td>Liczba pracownikow: </td><td>" + list.get(0) + "</td>"
				+ "</tr><tr class='alt'>"
				+ "<td>Liczba klientow: </td><td>" + list.get(1) + "</td>"
				+ "</tr><tr>"
				+ "<td>Liczba zawartych umow: </td><td>" + list.get(2) + "</td>"
				+ "</tr><tr class='alt'>"
				+ "<td>Liczba sprzedazy: </td><td>" + list.get(3) + "</td>"
				+ "</tr><tr>"
				+ "<td>Liczba realizowanych projektow: </td><td>" + list.get(4) + "</td>"
				+ "</tr><tr class='alt'>"
				+ "<td>Liczba wszystkich projektow: </td><td>" + list.get(8) + "</td>"
				+ "</tr><tr>"
				+ "<td>Baza skryptow: </td><td>" + list.get(5) + "</td>"
				+ "</tr><tr class='alt'>"
				+ "<td>Lczba wykonanych polaczen: </td><td>" + list.get(6) + "</td>"
				+ "</tr><tr>"
				+ "<th colspan='2'>Statystyki polaczen: </th>"
				+ "</tr><tr>"
				+ "<td>Srednia dlugosc polaczenia: </td><td>" + list.get(7) + " min</td>"
				+ "</tr>"
				+ "</table>";
		return str;
	}
	public static String workerMenu(int par){
		List<CCWorkerDTO> list = CCChefFunctions.getWorker();
		String str = "<div id='success'>";
		if(list.isEmpty()){
			str += "</div><h2>Brak pracownikow</h2>";
		}
		else {
			str += "</div><h2>Wybierz pracownika, ktorego statystyki wyswietlic</h2>"
					+ "<form action='CCChefFunctions' method='post'>"
					+ "<select id='worker' name='worker_e'>";
			for(CCWorkerDTO w : list){
				str += "<option value='" + w.getId() + "'>" + w.getSurname() + " " + w.getName() + "</option>";
			}
			str+= "</select>"
					+ "<input id='type' name='type' type='hidden' value='worker'/>"
					+ "<input type='submit' value='Pokaz'/><br/>"
					+ "</form>";
		}
		if(par == 1){
			List<Object> worker = CCChefFunctions.getWorkerData();
			str += "<br />"
					+ "<h2>" + worker.get(6) + " " + worker.get(7) + "</h2>"
					+ "<table id='stats'>"
					+ "<tr><th>Nazwa statystyki</th><th>Wartosc</th></tr>"
					+ "<tr><th colspan=2>Ogolne informacje</th></tr>"
					+ "<tr><td>W firmie przez (m-ce)</td><td>" + worker.get(0) + "</td></tr>"
					+ "<tr><td>Do konca umowy (m-ce)</td><td>" + worker.get(1) + "</td></tr>"
					+ "<tr><th colspan=2>Statystyki</th></tr>"
					+ "<tr><td>Liczba wykonanych polaczen</td><td>" + worker.get(2) + "</td></tr>"
					+ "<tr><td>Liczba projektow realizowanych</td><td>" + worker.get(3) + "</td></tr>"
					+ "<tr><td>Liczba klientow</td><td>" + worker.get(4) + "</td></tr>"
					+ "<tr><td>Suma dlugosci wykonanych polaczen</td><td>" + worker.get(5) + "min</td></tr>"
					+ "</table>";
		}
		return str;
	}
	public static String wybierzProjektMenu(int par){
		List <CCProjectsDTO> list = CCChefFunctions.getProjects();
		String str = "<div id='success'>";
		if(par == 1){
			str += "<h2>Pomyslnie aktywowano projekty</h2>";
		}
		else {
			str += "";
		}
		str += "</div><h2>Dostepne projekty: </h2>"
				+ "<form action ='CCChefFunctions' method='post'>"
				+ "<input id='type' name='type' type='hidden' value='active'/>";
		str += "<table id='stats'>"
				+ "<tr>"
				+ "<th>Numer</th><th>Tytul</th><th>Typ</th><th>Przedmiot</th><th>Firma</th><th>Aktywny</th>"
				+ "</tr>";
		for(CCProjectsDTO p : list){
			str+= "<tr><td>" + p.getId() + "</td><td>" + p.getTitle() + "</td><td>" + (p.getType().equals("sales")?"Sprzedaz":"Umowy") + "<td>"
					+ (p.getItem()==null?"x":p.getItem()) + "</td><td>" + (p.getCompany()==null?"x":p.getCompany()) + "</td><td>"
					+ "<input id='active' name='active' type='checkbox' value='"+p.getId() + "'" + (p.isActive()?"checked":"")+ "/></td>"
					+ "</tr>";
		}
		str+= "</table>"
				+ "<input type='submit' value='Aktywuj'/>"
				+ "</form>";
		return str;
	}
	public static String nowyProjektMenu(int par){
		String str = "<div id='success'>";
		if(par == 1){
			str += "<h2>Pomyslnie dodano projekt</h2>";
		}
		else if(par == 2){
			str += "<h2>Nie udalo sie dodac projektu</h2>";
		}
		else {
			str += "";
		}
		str += "</div><h2>Nowy projekt</h2>"
				+ "<form action='CCChefFunctions' method='post'>"
				+ "Tytul projektu:<br />"
				+ "<input id='title' name='title' type='text' size=30 /><br />"
				+ "Typ projektu: <br />"
				+ "<select id='type_p' name='type_p'>"
				+ "<option value='sales'>Sprzedaz</option>"
				+ "<option value='agreement'>Umowy</option>"
				+ "</select><br />"
				+ "Przedmiot/Firma: <br />"
				+ "<input id='item' name='item' type='text' size=30 /><br />"
				+ "Aktywny? <input id='active' name='active' type='checkbox'/><br />"
				+ "<input id='type' name='type' type='hidden' value='new_proj'/>"
				+ "<input type='submit' value='Dodaj'/>"
				+ "</form>";
		return str;
	}
}
